package com.ruoyi.htzj.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.htzj.domain.HtzjContents;
import com.ruoyi.htzj.service.HtzjContentsService;
import com.ruoyi.htzj.mapper.HtzjContentsMapper;
import org.springframework.stereotype.Service;

/**
* @author xq
* @description 针对表【htzj_contents(内容信息表，存储历史文化、特色美食、旅游景区等内容)】的数据库操作Service实现
* @createDate 2025-03-24 03:09:17
*/
@Service
public class HtzjContentsServiceImpl extends ServiceImpl<HtzjContentsMapper, HtzjContents>
    implements HtzjContentsService{

    @Override
    public TableDataInfo<HtzjContents> queryPageList(HtzjContents contents, PageQuery pageQuery) {
        // 创建分页对象
        Page<HtzjContents> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
        // 创建查询条件包装器
        LambdaQueryWrapper<HtzjContents> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(contents.getStreetId()!=null,HtzjContents::getStreetId, contents.getStreetId());
        queryWrapper.like(contents.getTitle()!=null,HtzjContents::getTitle, contents.getTitle());
        queryWrapper.eq(StrUtil.isNotBlank(contents.getContentType()),HtzjContents::getContentType, contents.getContentType());
        queryWrapper.orderByDesc(HtzjContents::getCreateTime);
        // 执行分页查询
        Page<HtzjContents> resultPage = this.page(page, queryWrapper);
        // 将分页结果封装到 TableDataInfo 中
        return TableDataInfo.build(resultPage);
    }

    @Override
    public void insertContents(HtzjContents contents) {
        // 插入新的内容记录
        this.save(contents);
    }

    @Override
    public void updateContents(HtzjContents contents) {
        // 根据内容的 ID 更新内容记录
        this.updateById(contents);
    }

    @Override
    public void deleteContentsByIds(Long[] contentIds) {
        // 根据内容的 ID 数组批量删除内容记录
        this.removeByIds(java.util.Arrays.asList(contentIds));
    }

    @Override
    public HtzjContents getContentById(Long contentId) {
        return this.getById(contentId);
    }


}




